/*
 * @lc app=leetcode.cn id=917 lang=cpp
 *
 * [917] 仅仅反转字母
 */
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>

using namespace std;
// @lc code=start
class Solution {
public:
    string reverseOnlyLetters(string s) {
        vector<pair<int,char>> record;
        string ret;
        for(int i = 0;i < s.length();i++) {
            if((s[i] >= 'A' && s[i] <= 'Z') || (s[i] >= 'a' && s[i] <= 'z')) {
                ret.push_back(s[i]);
            }else {
                record.push_back(make_pair(i,s[i]));
            }
        }
        reverse(ret.begin(),ret.end());
        for(auto str : record) {
            ret.insert(ret.begin()+str.first,str.second);
        }
        return ret;
    }
};
// @lc code=end

